<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var getIntersectionNode = function (headA, headB) {
        let curA = headA
        let curB = headB
        let lengthA = 0
        let lengthB = 0
        while (curA) {
          lengthA++
          curA = curA.next
        }
        while (curB) {
          lengthB++
          curB = curB.next
        }
        if (lengthA < lengthB) {
          ;[headA, headB] = [headB, headA]
          ;[lengthA, lengthB] = [lengthB, lengthA]
        }
        let len = lengthA - lengthB
        while (len) {
          len--
          headA = headA.next
        }
        while (headA && headB) {
          if (headA == headB) {
            return headA
          }
          headA = headA.next
          headB = headB.next
        }
        return headA
      }
    </script>
  </body>
</html>
